package cn.xz.kjg.adapter

import android.graphics.drawable.Drawable
import android.widget.TextView
import cn.xz.kjg.R
import cn.xz.kjg.bean.DeviceList
import cn.xz.kjg.bean.Flash
import cn.xz.kjg.util.AppHelper
import cn.xz.kjg.util.LocalHttp
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 *本地列表适配器*/
class LocalListAdapter1(mDevice: DeviceList): BaseQuickAdapter<Flash, BaseViewHolder>(R.layout.item_local_list1) {

    private var selectPosition = -1

    private var mDevice = mDevice

    override fun convert(holder: BaseViewHolder, item: Flash) {
        val mText = holder.getView<TextView>(R.id.channel_item_tv)

        mText.text = item.title

        var mH: Drawable? = null
        if (holder.adapterPosition == selectPosition){
            mH = AppHelper.getDrawable(R.mipmap.icon_s3)
        }
        mText.background = mH

        mText.setOnClickListener {
            selectPosition = holder.adapterPosition
            LocalHttp.playLocal(mDevice.ip,holder.adapterPosition)
            notifyDataSetChanged()
        }

    }
}